package com.blog.controller;

import com.blog.service.TagService;
import com.blog.service.impl.TagServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/DeleteTagServlet.do")
public class DeleteTagServlet extends HttpServlet {
     TagService tagService= new TagServiceImpl();
    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.setCharacterEncoding("utf-8");
        resp.setContentType("text/html;charset=utf-8");
        String articleTag = req.getParameter("articleTag");
        if (articleTag==null){
            resp.getWriter().write("<script>alert('标签删除失败！');location.href='/GoAdminServlet.do';</script>");
        }
        //根据标签名进行删除标签
           int i=  tagService.deleteTag(articleTag);
           //判断是否删除成功
        if (i !=0) {
            //删除成功
            //跳转页面
            req.getRequestDispatcher("/GoAdminServlet.do").forward(req,resp);

        }else{
            //删除失败
            resp.getWriter().write("<script>alert('标签删除失败！');location.href='/GoAdminServlet.do';</script>");
        }

    }
}
